package com.yn.xr.front.user.interceptor;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.yn.xr.front.user.action.UserAction;
/**
 * 
 * @description:   登录拦截
 * @fileName:CheckLoginInterceptor.java 
 * @createTime:2015年2月2日 下午8:53:59  
 * @author:刘玉峰  
 * @version 1.0.0  
 *
 */
public class CheckLoginInterceptor extends AbstractInterceptor {
	
	private static final long serialVersionUID = -1613767611698805638L;
	
	private static final Logger log = LoggerFactory.getLogger(CheckLoginInterceptor.class);
	
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		
		Object action = actionInvocation.getAction();
		String nameSpace = actionInvocation.getProxy().getNamespace();
		String actionName=actionInvocation.getProxy().getActionName();     
		HttpServletRequest request =	ServletActionContext.getRequest();
		String url = request.getRequestURL().toString();
		log.info("【CheckLoginInterceptor.intercept】 nameSpace_action_actionName"+nameSpace+"_"+action+"_"+actionName);
		log.info("【CheckLoginInterceptor.intercept】 url"+url);
		return actionInvocation.invoke();
		
		/*Object action = actionInvocation.getAction();
		String nameSpace = actionInvocation.getProxy().getNamespace();
		String actionName=actionInvocation.getProxy().getActionName();     
		HttpServletRequest request =	ServletActionContext.getRequest();
		String url = request.getRequestURL().toString();
		String before = request.getHeader("Referer");
		if (action instanceof UserAction || url.indexOf("login.jsp")!=-1) {
			return actionInvocation.invoke();
		}
		Map session = actionInvocation.getInvocationContext().getSession();
		
		if(session.get(SystemConstants.USERID_SESSION_INFO)==null && actionName!=null && !actionName.isEmpty() &&  actionName.indexOf("userLoginSuccessAction_toMyPurse")<=-1){
			request.getSession().setAttribute("actionName", actionName);
			request.getSession().setAttribute("nameSpace", nameSpace);
		}
		if (session.get(SystemConstants.USERID_SESSION_INFO)!=null) {
				return actionInvocation.invoke();
		} else {
			return "login";
		}*/
	}

}
